(function(){
    $(".back").click(function(){
        $("body,html").animate({scrollTop:0},500)
    })
    var num=0;
    
    function fn(num){
        $.ajax({
            type:"GET",
            url: "http://chst.vip:1234/api/getmoneyctrl",
            data: {pageid:num},
        }).then(res=>{
            let html=""
            let data=res.result;
            var productId=[];
            data.forEach(function(item,index){
                html+=`
                <li>
                    ${item.productImg2}
                    <div><p>${item.productName}<span>${item.productPinkage}</span></p>
                    
                    <span>${item.productFrom} | ${item.productTime} | ${item.productComCount} </span>
                    </div>
                </li>
                `
                productId[index]=item.productId;
                $(".recommendshopping").html(html);
             
            })
            for(let i=0;i<productId.length;i++){
                $(".recommendshopping").children("li:eq("+i+")").click(function(){
    
                    window.location.href="http://127.0.0.1:5500/%E9%A1%B9%E7%9B%AE/pages/domesticDetail.html?productid="+productId[i]
                })
            }
        })
    }
    fn(num);
    
    //点击select实现跳转
    $("select").change(function(){
        console.log(this.selectedIndex)
        num=this.selectedIndex;
        fn(num);
    })

    //下一页
    $("button:eq(1)").click(function(){
        $("select").children("option:eq("+num+")").removeProp("selected")
        num++;
        if(num>15)num=15;
        $("select").children("option:eq("+num+")").prop("selected","true")
        fn(num);
    })

    //上一页
    $("button:eq(0)").click(function(){
        $("select").children("option:eq("+num+")").removeProp("selected")
        num--;
        if(num<0)num=0;
        $("select").children("option:eq("+num+")").prop("selected","true")
        fn(num)
    })


})()
